<?php
$tag =$_GET['tag'];
$seo = $_POST['seo'];
if ($_GET['a']=="save")
{    
    $seo=check_content($seo);
	sql_update('seo', $seo, 'id', "'" . $seo['id'] . "'");
	$page_title='<title>'.$_POST['seo']['title']."</title>\r\n";
    $page_title.='<meta name="keywords" content="'.$_POST['seo']['keyword'].'" />'."\r\n";
    $page_title.='<meta name="description" content="'.$_POST['seo']['desc'].'" />'."\r\n";
	$pagetag=$seo['tag'];
	$code=template_parse(str_replace("\'","'",$page_title));
    file_put_contents(DDROOTPATH.'/cache/title/'.$pagetag.'_title.php',$code);
	echo alert('保存完成', '?act=lable&tag='.$seo['tag']);
}
if ($_GET['del'])
{
	$seo = sel_sql('seo', '*', "id='" . $_GET['del'] . "'");
	if($seo['del']==0){
	    delete_sql('seo',"id=".$_GET['del']);
	    echo alert('删除了', '?act=list');
	}else{
		echo alert('你居然要删我！我是多多默认的标签啊！', '?act=list');
	}
}
$seo = sel_sql('seo', '*', "tag='" . $tag . "'");
$labelarr = explode("|", $seo['label']);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>SEO后台管理</title>
<link href="css/reset.css" rel="stylesheet" type="text/css" />
<link href="css/system.css" rel="stylesheet" type="text/css" />
<link href="css/table_form.css" rel="stylesheet" type="text/css" />
<style type="text/css">
html{_overflow-y:scroll}
</style>
<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="js/formvalidator.js" charset="UTF-8"></script>
</head>

<body>
<script type="text/javascript">
$(document).ready(function() {
	$.formValidator.initConfig({formid:"myform",autotip:true,onerror:function(msg){}});
	$("#site_title").formValidator({onshow:"请输入网站标题",onfocus:"用于首页标题或其他页面标题",oncorrect:"标题设置正确"}).inputValidator({});
});
function insertText(id, text){
	var mystr = $('#'+id).val();
	$('#'+id).focus();
	$('#'+id).val(mystr + text);
}
function showconfirm(id)
{
	document.thisForm.target='_self';	
	if (id==1)
	{
		if(confirm("您确定要保存信息吗？")==true)
		{
			document.thisForm.action="?act=lable&tag=<?=$tag?>&a=save";
			thisForm.submit();
		}
	}
	if (id==2)
	{
		if(confirm("您确定要删除信息吗？")==true)
		{
			document.thisForm.action="?act=lable&tag=<?=$tag?>&del=<?=$seo[id]?>";
			thisForm.submit();
		}
	}
}
</script>
<style>
.input-text{font-size:12px; font-family:'宋体';}.btn-l{color:#38E;border-bottom:2px #38E solid;text-decoration:none;}.red{color:#D30;border-color:#D30}
</style>
<div class="subnav">
  <div class="content-menu ib-a blue line-x"><a href="../../<?=$seo["url"]?>" target="_blank" ><em>
   <?=$seo["tag"]?>
    页面规则</em></a><span>|</span>请阅读提示进行设置
    <div id="callback" class="hidden pa" style="height:30px;top:13px;left:235px"></div>
  </div>
</div>
<div class="pad_10">
  <div class="explain-col"> 温馨提示：每个标题设置均有独立的标签, 不能在其他标题设置里使用. &nbsp; 标签设置错误将无法解析.<br />
    示例说明：<b><font color="blue">{$webtitle}-{$itemcatsname}-第{$page}页-按{$sort}排序</font></b>, 必须保留完整不能修改.<br />
  </div>
  <div class="bk10"></div>
  <div class="col-tab">
    <div id="div_setting_1" class="contentList pad_10">
      <form name="thisForm" action="?act=lable&tag=<?=$tag?>&a=save" method="post" id="myform">
        <table width="100%"  class="table_form">
          <tr>
            <th width="80">标签tag</th>
            <td><input type="text" name="seo[tag]" id="site_tag" size="25" class="input-text" style="width:400px" value="<?=$seo["tag"]?>" /><input type="hidden" name="seo[id]"value="<?=$seo[id]?>" />
              必填选项</td>
          </tr>
          <tr>
            <th width="80">对应页面</th>
            <td><input type="text" name="seo[url]" id="site_url" size="25" class="input-text" style="width:400px" value="<?=$seo["url"]?>" /></td>
          </tr>
          <tr>
            <th>标题</th>
            <td><input type="text" name="seo[title]" id="title" size="25" class="input-text" style="width:95%" value="<?=$seo["title"]?>" /></td>
          </tr>
          <tr>
            <th></th>
            <td>
			<?php foreach($labelarr as $v) {$label = explode("-", $v);?>
              &nbsp; &nbsp;<u class="cu btn-l" onClick="insertText('title', '<?=$label[0]?>')" title="<?=$label[0]?>"><?=$label[1]?></u>
              <?php }?>
              </td>
          </tr>
          <tr>
            <th>关键字</th>
            <td><input type="text" name="seo[keyword]" id="keyword" size="25" class="input-text" style="width:95%" value="<?=$seo[keyword]?>" /></td>
          </tr>
          <tr>
            <th></th>
            <td>
            <?php foreach($labelarr as $v) {$label = explode("-", $v);?>
              &nbsp; &nbsp;<u class="cu btn-l" onClick="insertText('keyword', '<?=$label[0]?>')" title="<?=$label[0]?>"><?=$label[1]?></u>
              <?php }?>
          </td>
          </tr>
          <tr>
            <th>描述</th>
            <td><input type="text" name="seo[desc]" id="desc" size="25" class="input-text" style="width:95%" value="<?=$seo[desc]?>" /></td>
          </tr>
          <tr>
            <th></th>
            <td>
             <?php foreach($labelarr as $v) {$label = explode("-", $v);?>
              &nbsp; &nbsp;<u class="cu btn-l" onClick="insertText('desc', '<?=$label[0]?>')" title="<?=$label[0]?>"><?=$label[1]?></u>
              <?php }?>
          </td>
          </tr>
          <tr>
            <th>简便标签</th>
            <td><input type="text" name="seo[label]" id="desc" size="25" class="input-text" style="width:95%" value="<?=$seo[label]?>" /></td>
          </tr>
          <tr>
            <th></th>
            <td><span class="onCorrect">还有更高级的自定义标签规则设置, 请到论坛查看相关教程. &nbsp; [<a href="http://bbs.duoduo123.com/read-htm-tid-67394-ds-1.html" target="_blank"><u class="blue">点击进入论坛</u></a>]</span></td>
          </tr>
          <tr>
            <th></th>
            <td><input name="delall" type="button" id="delall"  onclick="javascript:showconfirm(1)" value="提交" class="button"><input name="delall" type="button" id="delall" value="删除本标签" onclick="javascript:showconfirm(2)" class="button"></td>
          </tr>
        </table>
      </form>
      <div class="bk15"></div>
    </div>
  </div>
</div>
</body>
</html>